home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1998 #3 / Amiga Plus CD - 1998 - No. 3.iso / pd / spiele / frotz / source / amiga_list.c next >
C/C++ Source or Header  |  1997-11-06  |  8KB  |  384 lines

  1. /*
  2.  * amiga_list.c
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "frotz.h"
  9. #include "amiga.h"
  10.  
  11. int SerialNumbers[][3] =
  12. {
  13.  0, 77,850814,    /* A Mind Forever Voyaging */
  14.  0, 79,851122,
  15.  
  16.  1, 54,890606,    /* Arthur */
  17.  1, 63,890622,
  18.  1, 74,890714,
  19.  
  20.  2, 97,851218,    /* Ballyhoo */
  21.  
  22.  3, 47,870915,    /* Beyond Zork */
  23.  3, 49,870917,
  24.  3, 51,870923,
  25.  3, 57,871221,
  26.  
  27.  4,  9,871008,    /* Border Zone */
  28.  
  29.  5, 86,870212,    /* Bureaucracy */
  30.  5,116,870602,
  31.  
  32.  6, 23,840809,    /* Cutthroats */
  33.  
  34.  7, 26,821108,    /* Deadline */
  35.  7, 27,831005,
  36.  
  37.  8, 10,830810,    /* Enchanter */
  38.  8, 16,831118,
  39.  8, 24,851118,
  40.  8, 29,860820,
  41.  
  42.  9, 47,840914,    /* The Hitchhiker's Guide to the Galaxy */
  43.  9, 56,841221,
  44.  9, 58,851002,
  45.  9, 59,851108,
  46.  9, 31,871119,
  47.  
  48. 10, 37,861215,    /* Hollywood Hijinx */
  49.  
  50. 11, 22,830916,    /* Infidel */
  51.  
  52. 12, 26,890316,    /* Journey */
  53. 12, 30,890322,
  54. 12, 77,890616,
  55. 12, 83,890706,
  56.  
  57. 13,118,860325,    /* Leather Goddesses of Phobos */
  58. 13, 50,860711,
  59. 13, 59,860730,
  60. 13,  4,880405,
  61.  
  62. 14,203,870506,    /* The Lurking Horror */
  63. 14,219,870912,
  64. 14,221,870918,
  65.  
  66. 15,  4,860918,    /* Moonmist */
  67. 15,  9,861022,
  68.  
  69. 16, 19,870722,    /* Nord and Bert Couldn't Make Head or Tail of It */
  70.  
  71. 17, 20,830708,    /* Planetfall */
  72. 17, 29,840118,
  73. 17, 37,851003,
  74. 17, 10,880531,
  75.  
  76. 18, 26,870730,    /* Plundered Hearts */
  77.  
  78. 19, 15,840501,    /* Seastalker */
  79. 19, 15,840522,
  80. 19, 16,850515,
  81. 19, 16,850603,
  82.  
  83. 20, 21,871214,    /* Sherlock */
  84. 20, 26,880127,
  85.  
  86. 21,292,890314,    /* Shogun */
  87. 21,295,890321,
  88. 21,311,890510,
  89. 21,322,890706,
  90.  
  91. 22,  4,840131,    /* Sorcerer */
  92. 22,  6,840508,
  93. 22, 13,851021,
  94. 22, 15,851108,
  95. 22, 18,860904,
  96.  
  97. 23, 63,850916,    /* Spellbreaker */
  98. 23, 87,860904,
  99.  
  100. 24, 15,820901,    /* Starcross */
  101. 24, 17,821021,
  102.  
  103. 25,107,870430,    /* Stationfall */
  104.  
  105. 26, 14,841005,    /* Suspect */
  106.  
  107. 27,  5,830222,    /* Suspended */
  108. 27,  7,830419,
  109. 27,  8,830521,
  110. 27,  8,840521,
  111.  
  112. 28, 11,860509,    /* Trinity */
  113. 28, 12,860926,
  114.  
  115. 29, 68,850501,    /* Wishbringer */
  116. 29, 69,850920,
  117. 29, 23,880706,
  118.  
  119. 30, 13,830524,    /* The Witness */
  120. 30, 20,831119,
  121. 30, 21,831208,
  122. 30, 22,840924,
  123.  
  124. 31, 25,820515,    /* Zork I */
  125. 31, 28,821013,
  126. 31, 30,830330,
  127. 31, 75,830929,
  128. 31, 76,840509,
  129. 31, 88,840726,
  130. 31, 52,871125,
  131.  
  132. 32, 18,820517,    /* Zork II */
  133. 32, 22,830331,
  134. 32, 48,840904,
  135.  
  136. 33, 10,820818,    /* Zork III */
  137. 33, 15,830331,
  138. 33, 15,840518,
  139. 33, 17,840727,
  140.  
  141. 34,296,881019,    /* Zork Zero */
  142. 34,366,890323,
  143. 34,383,890602,
  144. 34,393,890714,
  145.  
  146. -1,0,0
  147. };
  148.  
  149. char *GameInformation[][2] =
  150. {
  151.   "A Mind Forever Voyaging","Steve Meretzky",
  152.   "Arthur: The Quest for Excalibur","Bob Bates",
  153.   "Ballyhoo","Jeff O'Neill",
  154.   "Beyond Zork: The Coconut of Quendor","Brian Moriarty",
  155.   "Border Zone","Marc Blank",
  156.   "Bureaucracy","Douglas Adams & Infocom",
  157.   "Cutthroats","Michael Berlyn & Jerry Wolper",
  158.   "Deadline","Marc Blank",
  159.   "Enchanter","Marc Blank & Dave Lebling",
  160.   "Hitchhiker's Guide to the Galaxy","Douglas Adams & Steve Meretzky",
  161.   "Hollywood Hijinx","Dave Anderson & Liz Cyr-Jones",
  162.   "Infidel","Michael Berlyn & Patricia Fogleman",
  163.   "Journey","Marc Blank",
  164.   "Leather Goddesses of Phobos","Steve Meretzky",
  165.   "Lurking Horror","Dave Lebling",
  166.   "Moonmist","Stu Galley & Jim Lawrence",
  167.   "Nord and Bert","Jeff O'Neill",
  168.   "Planetfall","Steve Meretzky",
  169.   "Plundered Hearts","Amy Briggs",
  170.   "Seastalker","Stu Galley & Jim Lawrence",
  171.   "Sherlock: The Riddle Of The Crown Jewels","Bob Bates",
  172.   "Shogun","Dave Lebling",
  173.   "Sorcerer","Steve Meretzky",
  174.   "Spellbreaker","Dave Lebling",
  175.   "Starcross","Dave Lebling",
  176.   "Stationfall","Steve Meretzky",
  177.   "Suspect","Dave Lebling",
  178.   "Suspended","Michael Berlyn",
  179.   "Trinity","Brian Moriarty",
  180.   "Wishbringer: The Magick Stone of Dreams","Brian Moriarty",
  181.   "Witness","Stu Galley",
  182.   "Zork I: The Great Underground Empire","Marc Blank & Dave Lebling",
  183.   "Zork II: The Wizard of Frobozz","Marc Blank & Dave Lebling",
  184.   "Zork III: The Dungeon Master","Marc Blank & Dave Lebling",
  185.   "Zork Zero: The Revenge of Megaboz","Steve Meretzky"
  186. };
  187.  
  188. short GameLevels[] =
  189. { 3,0,2,0,0,0,2,4,2,2,2,3,0,2,0,1,0,2,0,1,0,0,3,4,4,0,3,4,2,1,2,2,3,3,0 };
  190.  
  191. extern struct List *GamesList;
  192.  
  193. int ScanForGame(int release,char *serial,int checksum)
  194. {
  195. int game_number = -1;
  196. int i;
  197. struct GameNode *node;
  198.  
  199.   for(i = 0; SerialNumbers[i][0] != -1; i++)
  200.   {
  201.     if (CompareGames(release,SerialNumbers[i][1],SerialNumber(serial),SerialNumbers[i][2],0,0))
  202.       game_number = SerialNumbers[i][0];
  203.   }
  204.   node = (struct GameNode *)GamesList->lh_Head;
  205.   while (node->Node.ln_Succ)
  206.   {
  207.     i = 0;
  208.     while ((i < MAX_GAME_ENTRIES) && (node->Serial[i] != 0))
  209.     {
  210.       if (CompareGames(release,node->Release[i],SerialNumber(serial),node->Serial[i],checksum,node->Checksum[i]))
  211.     game_number = (int)node->Node.ln_Pri;
  212.       i++;
  213.     }
  214.     node = (struct GameNode *)node->Node.ln_Succ;
  215.   }
  216.   return game_number;
  217. }
  218.  
  219. int CompareGames(int r1,int r2,int s1,int s2,int c1,int c2)
  220. {
  221.   if (r1 != r2) return 0;
  222.   if (s1 != s2) return 0;
  223.   if ((c1 == 0) || (c2 == 0)) return 1;
  224.   return c1 == c2 ? 1 : 0;
  225. }
  226.  
  227. char *GetGameTitle(int game)
  228. {
  229. struct GameNode *node;
  230.  
  231.   if (game >= 0) return GameInformation[game][0];
  232.   if (game < -1)
  233.   {
  234.     node = (struct GameNode *)GamesList->lh_Head;
  235.     while (node->Node.ln_Succ)
  236.     {
  237.       if (game == (int)node->Node.ln_Pri) return node->Node.ln_Name;
  238.       node = (struct GameNode *)node->Node.ln_Succ;
  239.     }
  240.   }
  241.   return "";
  242. }
  243.  
  244. char *GetGameAuthors(int game)
  245. {
  246. struct GameNode *node;
  247.  
  248.   if (game >= 0) return GameInformation[game][1];
  249.   if (game < -1)
  250.   {
  251.     node = (struct GameNode *)GamesList->lh_Head;
  252.     while (node->Node.ln_Succ)
  253.     {
  254.       if (game == (int)node->Node.ln_Pri) return node->Author;
  255.       node = (struct GameNode *)node->Node.ln_Succ;
  256.     }
  257.   }
  258.   return "";
  259. }
  260.  
  261. char *GetGameLevel(int game)
  262. {
  263.   if (game >= 0)
  264.   {
  265.     switch (GameLevels[game])
  266.     {
  267.       case 1:
  268.     return "Introductory Level\n\n";
  269.       case 2:
  270.     return "Standard Level\n\n";
  271.       case 3:
  272.     return "Advanced Level\n\n";
  273.       case 4:
  274.     return "Expert Level\n\n";
  275.     }
  276.   }
  277.   return "";
  278. }
  279.  
  280. int SerialNumber(char *serial_string)
  281. {
  282. int serial_number = 0;
  283. int i;
  284.  
  285.   for (i = 0; i < 6; i++)
  286.   {
  287.     serial_number = serial_number*10;
  288.     serial_number += *(serial_string+i)-'0';
  289.   }
  290.   return serial_number;
  291. }
  292.  
  293. void ReadGamesFile(void)
  294. {
  295. static int first_time = 0;
  296.  
  297.   if (first_time == 1) return;
  298.   first_time = 1;
  299.  
  300.   CreateList(&GamesList);
  301.  
  302. FILE *file;
  303.  
  304.   if ((file = fopen("Infocom.games","r")) == 0)
  305.   {
  306.     if ((file = fopen("PROGDIR:Infocom.games","r")) == 0) return;
  307.   }
  308.  
  309. struct GameNode *node = 0;
  310. char line[256];
  311. char *end;
  312. char priority = -2;
  313. int release, serial, checksum;
  314. int current_entry;
  315.  
  316.   while (feof(file) == 0)
  317.   {
  318.     *line = '\0';
  319.     fgets(line,256,file);
  320.  
  321.     if (*line == '[')
  322.     {
  323.       if (end = strrchr(line,']'))
  324.       {
  325.     *end = '\0';
  326.     node = (struct GameNode *)CreateNode(GamesList,line+1,sizeof(struct GameNode));
  327.     node->Node.ln_Pri = priority;
  328.     priority--;
  329.     current_entry = 0;
  330.       }
  331.     }
  332.  
  333.     if (strncmp(line,"Author=",7) == 0)
  334.     {
  335.       if (node) strcpy(node->Author,line+7);
  336.       if (end = strrchr(node->Author,'\n')) *end = '\0';
  337.     }
  338.  
  339.     checksum = 0;
  340.     if (sscanf(line,"%d / %d / $%X",&release,&serial,&checksum) >= 2)
  341.     {
  342.       if (node)
  343.       {
  344.     if (current_entry < MAX_GAME_ENTRIES)
  345.     {
  346.       node->Release[current_entry] = release;
  347.       node->Serial[current_entry] = serial;
  348.       node->Checksum[current_entry] = checksum;
  349.       current_entry++;
  350.     }
  351.       }
  352.     }
  353.   }
  354.   fclose(file);
  355. }
  356.  
  357. void WriteGamesFile(void)
  358. {
  359. FILE *file;
  360. struct GameNode *node;
  361. int current_entry;
  362.  
  363.   if ((file = fopen("PROGDIR:Infocom.games","w")) == 0) return;
  364.  
  365.   node = (struct GameNode *)GamesList->lh_Head;
  366.   while (node->Node.ln_Succ)
  367.   {
  368.     fprintf(file,"[%s]\n",node->Node.ln_Name);
  369.     if (strcmp(node->Author,"") != 0) fprintf(file,"Author=%s\n",node->Author);
  370.     current_entry = 0;
  371.     while ((current_entry < MAX_GAME_ENTRIES) && (node->Serial[current_entry] != 0))
  372.     {
  373.       fprintf(file,"%d / %d",node->Release[current_entry],node->Serial[current_entry]);
  374.       if (node->Checksum[current_entry] > 0)
  375.     fprintf(file," / $%X",node->Checksum[current_entry]);
  376.       fprintf(file,"\n");
  377.       current_entry++;
  378.     }
  379.     fprintf(file,"\n");
  380.     node = (struct GameNode *)node->Node.ln_Succ;
  381.   }
  382.   fclose(file);
  383. }
  384.